import time

from appium import webdriver
import unittest
from appium.webdriver.common.appiumby import AppiumBy

"""
    1、如果 想要 通过 python 编写  app 的自动化测试脚本  ，需要使用  appium 客户端的服务 以及 appium 的模块
    2、 pypi：pip install Appium-Python-Client
"""


class MyAppiumTestCase(unittest.TestCase):
    driver = None

    @classmethod
    def setUpClass(cls) -> None:
        desired_caps = dict(
            platformName='Android',
            deviceName='127.0.0.1:62001',
            appActivity='com.amaze.filemanager.activities.MainActivity',
            appPackage='com.amaze.filemanager',
            noReset='true',
        )
        cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

        # 隐式等待
        cls.driver.implicitly_wait(30)

    def test_ibooks(self):
        print('i启动成功-----')
        time.sleep(10)

        # 向右 和  向左 滑动
        # 在滑动之前 获得 整个屏幕的 分辨率的 大小
        window_size = self.driver.get_window_size()
        print(window_size)

        # 从 右 往  左

        # 开始坐标的  x,y
        start_x = window_size['width'] * 0.75
        start_y = window_size['height'] * 0.5

        end_x = window_size['width'] * 0.25

        self.driver.swipe(start_x, start_y, end_x, start_y, 300)

        self.driver.save_screenshot('./resources/left.png')
        time.sleep(5)

        # 从 左 往  右

        # 开始坐标的  x,y
        start_x = window_size['width'] * 0.25
        start_y = window_size['height'] * 0.5

        end_x = window_size['width'] * 0.75

        self.driver.swipe(start_x, start_y, end_x, start_y, 300)

        self.driver.save_screenshot('resources/right.png')

    @classmethod
    def tearDownClass(cls) -> None:
        # cls.driver.quit()
        pass


if __name__ == '__main__':
    unittest.main()
